﻿CREATE FUNCTION [dbo].[fn_PrimaryKeyConstraintName]
(
	@Table sysname
)
RETURNS sysname
AS
BEGIN
	RETURN (
	    SELECT kc.[name]
	    FROM   sys.tables t
	           INNER JOIN sys.key_constraints kc
	                ON  kc.parent_object_id = t.[object_id]
	    WHERE  t.[type] = 'U'
	           AND kc.[type] = 'PK'
	           AND t.[name] = @Table
		       AND t.[type] = 'U'
	)
END